//
//  UIButton+Extension.swift
//  YYPWeibo
//
//  Created by youyongpeng on 15/11/21.
//  Copyright © 2015年 youyongpeng. All rights reserved.
//

import UIKit

extension UIButton {

    // 便利 构造函数
    convenience init(imageName: String, backImageName: String) {
    
        // 调用父类的
        self.init()
        
        // 设置图片
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)

        // 会根据图片来设置按钮的frame
        sizeToFit()
        
    }
    
    /// 按钮的便利函数
    ///
    /// - parameter title:     按钮名字
    /// - parameter imageName: 按钮图片名称
    /// - parameter color:     按钮背景图
    ///
    /// - returns: 按钮
    convenience init(title: String, imageName: String, color: UIColor) {
        
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setBackgroundImage(UIImage(named: imageName), forState: .Normal)
        
    }
    
    
}




